<?php
quanli_require('core/db.config.php');
quanli_require('core/DBCA.' . G_DB_TYPE . '.php');

class DBCAFactory{
	//website
	public static function web_create(){
    	$className = 'DBCA_' . G_DB_TYPE;
    	if (G_DB_TYPE == 'mysql'){
    		$rodb_config = null;
    		if (G_DB_RWSPLIT)
    			$rodb_config = array('G_DB_SERVERNAME'=>G_RODB_SERVERNAME,
    							'G_DB_USER'=>G_RODB_USER,
    							'G_DB_PWD'=>G_RODB_PWD,
    							'G_DB_DATABASE'=>G_RODB_DATABASE,
    							'G_DB_PORT'=>G_RODB_PORT);
    			
    		
    		return new $className(
    							array('G_DB_SERVERNAME'=>G_DB_SERVERNAME,
    							'G_DB_USER'=>G_DB_USER,
    							'G_DB_PWD'=>G_DB_PWD,
    							'G_DB_DATABASE'=>G_DB_DATABASE,
    							'G_DB_PORT'=>G_DB_PORT),
    							$rodb_config
    						);
    	}else
        	return new $className;
    }
    //quanliadmin
	public static function pg_create(){
    	$className = 'DBCA_' . G_DB_TYPE;
    	if (G_DB_TYPE == 'mysql'){
    		$rodb_config = null;
    		if (G_DB_RWSPLIT)
    			$rodb_config = array('G_DB_SERVERNAME'=>PG_RODB_SERVERNAME,
    							'G_DB_USER'=>PG_RODB_USER,
    							'G_DB_PWD'=>PG_RODB_PWD,
    							'G_DB_DATABASE'=>PG_RODB_DATABASE,
    							'G_DB_PORT'=>PG_RODB_PORT);
    		
    		
    		return new $className(
                array('G_DB_SERVERNAME'=>PG_DB_SERVERNAME,
                'G_DB_USER'=>PG_DB_USER,
                'G_DB_PWD'=>PG_DB_PWD,
                'G_DB_DATABASE'=>PG_DB_DATABASE,
                'G_DB_PORT'=>PG_DB_PORT),
                $rodb_config
            );
    	}else
        	return new $className;
    }

    //middle db
	public static function mid_create(){
    	$className = 'DBCA_' . G_DB_TYPE;
    	if (G_DB_TYPE == 'mysql'){
    		return new $className(
                array('G_DB_SERVERNAME'=>MID_DB_SERVERNAME,
                'G_DB_USER'=>MID_DB_USER,
                'G_DB_PWD'=>MID_DB_PWD,
                'G_DB_DATABASE'=>MID_DB_DATABASE,
                'G_DB_PORT'=>MID_DB_PORT),
                null
            );
    	}else
        	return new $className;
    }

}